<style>
table{
	border: 1px solid black;
	width: 700px;
	text-align: center;
	margin:0 auto;
}
th{
	background-color: white;
	border: 1px solid black;
}
td{
	border: 1px solid black;
}
</style>
<table>
<form action="index.php" method="post">
<tr><th>ID</th>
<th>专业</th><th>班级</th><th>学号</th><th>姓名</th><th>性别</th><th>出生日期</th></tr>
</form>
</table>


<?php
$servername = "192.168.56.103"; // MySQL 主机名
$username = "root"; // MySQL 用户名
$password = "123456"; // MySQL 密码
$dbname = "myDB"; // 要连接的数据库名称

// 创建连接
$link = new mysqli($servername, $username, $password, $dbname); 
echo $link?'':'数据库连接失败';
mysqli_query($link,"set names utf8");
if (isset($_POST['ziduan'])) {
    $ziduan = $_POST['ziduan'];
}
if (isset($_POST['neirong'])) {
    $neirong = $_POST['neirong'];
}
$ziduan = $_POST['ziduan'];
$neirong = $_POST['neirong'];
$query = "SELECT * FROM students WHERE {$ziduan} LIKE '%{$neirong}%'";
$result = mysqli_query($link, $query) or die("执行语句失败");
$count = 0;
echo "<table>";
while ($arr = mysqli_fetch_assoc($result)) {
    $count++;
    $alt = ($count % 2) ? "alt" : ""; 
    echo "<tr class={$alt}><td>{$arr['id']}</td><td>{$arr['major']}</td>".
         "<td>{$arr['class']}</td><td>{$arr['student_id']}</td>".
         "<td>{$arr['name']}</td><td>{$arr['sex']}</td><td>{$arr['birthday']}</td>";
}
echo "</table>";
mysqli_free_result($result);
?>

